import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'dnp_order_in_progress_page.dart';
import 'model/dnp_order_list_title_model.dart';

class DnpOrderListPage extends StatefulWidget {
  const DnpOrderListPage({super.key});

  @override
  State<DnpOrderListPage> createState() => _DnpOrderListPageState();
}

class _DnpOrderListPageState extends State<DnpOrderListPage> {
  late List<DnpOrderListTitleModel> _orderList;

  @override
  void initState() {
    super.initState();
    _orderList = [
      DnpOrderListTitleModel(
        src: "assets/images/ic_order_list_icon1.webp",
        title: "In progress",
        state: "1",
      ),
      DnpOrderListTitleModel(
          src: "assets/images/ic_order_list_icon2.webp",
          state: "2",
          title: "Repayment"),
      DnpOrderListTitleModel(
          src: "assets/images/ic_order_list_icon3.webp",
          state: "3",
          title: "Finished"),
      DnpOrderListTitleModel(
          src: "assets/images/ic_order_list_icon4.webp",
          state: "4",
          title: "Overdue"),
      DnpOrderListTitleModel(
          src: "assets/images/ic_order_list_icon5.webp",
          state: "5",
          title: "Audit failed"),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage('assets/images/ic_default_main_bg.webp'),
            fit: BoxFit.cover,
          ),
        ),
        child: Container(
          width: double.infinity,
          height: double.infinity,
          margin: EdgeInsets.only(
              left: 14,
              right: 14,
              bottom: 14,
              top: 9 + MediaQuery.of(context).padding.top),
          child: Column(
            children: [
              Image.asset(
                "assets/images/ic_order_list_top_bg.webp",
                width: double.infinity,
                height: 130,
                fit: BoxFit.fill,
              ),
              Expanded(
                  child: Container(
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                        bottomLeft: Radius.circular(20),
                        bottomRight: Radius.circular(20)),
                    border: Border(
                      left: BorderSide(color: Color(0xFF1D4AC8), width: 1.0),
                      right: BorderSide(color: Color(0xFF1D4AC8), width: 1.0),
                      bottom: BorderSide(color: Color(0xFF1D4AC8), width: 1.0),
                    )),
                child: ListView.builder(
                    itemCount: _orderList.length,
                    padding: EdgeInsets.zero,
                    itemBuilder: (context, index) {
                      return _buildOrderItem(_orderList[index]);
                    }),
              ))
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildOrderItem(DnpOrderListTitleModel model) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: () {
        Get.to(DnpOrderInProgressPage(
          title: model.title,
          state: model.state,
        ));
      },
      child: Container(
        height: 49,
        width: double.infinity,
        decoration: BoxDecoration(
          color: Color(0xFFE9F5FF),
          borderRadius: BorderRadius.circular(14),
        ),
        padding: EdgeInsets.symmetric(vertical: 6, horizontal: 10),
        margin: EdgeInsets.only(left: 14, right: 14, bottom: 14),
        child: Row(
          children: [
            Image.asset(
              model.src,
              width: 32.34,
              height: 32.34,
            ),
            SizedBox(
              width: 6,
            ),
            Text(
              model.title,
              style: TextStyle(
                  fontWeight: FontWeight.w500,
                  fontSize: 16,
                  color: Color(0xFF252630)),
            ),
            Spacer(),
            Image.asset(
              "assets/images/ic_order_list_icon_arrow.webp",
              width: 18,
              height: 18,
            ),
          ],
        ),
      ),
    );
  }
}
